package com.maven.front.controller.manageTeacher;

import com.maven.front.bean.EduTeacher;
import com.maven.front.bean.FileUploadResult;
import com.maven.front.bean.Result;
import com.maven.front.bean.SysSubject;
import com.maven.front.service.manageSubject.SysSubjectService;
import com.maven.front.service.teacher.EduTeacherService;
import com.maven.front.util.FileUploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("admin/teacher")
@Slf4j
public class EduTeacherController {

    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private SysSubjectService sysSubjectService;
    @Autowired
    private FileUploadService fileUploadService;

    @GetMapping("list")
    public Result list(EduTeacher eduTeacher){

        return  this.eduTeacherService.list(eduTeacher);
    }




    @PostMapping("save")
   public Result save(EduTeacher eduTeacher){

        int result = this.eduTeacherService.save(eduTeacher);
        if (result>0) {
            return new Result(200, "成功");
        } else {
            return new Result(100001, "保存失败");
        }

    }
    @PostMapping("update")
    public Result update(EduTeacher eduTeacher){
        int result=this.eduTeacherService.update(eduTeacher);
        if(result>0){
            return new Result(200,"成功");
        }else{
            return new Result(10002,"修改失败");
        }
    }


    @PostMapping("delete")
    public Result delete(int id){
        int result=this.eduTeacherService.delete(id);
        if(result>0){
            return new Result(200,"成功");
        }else{
            return new Result(10003,"删除失败");
        }
    }

    @GetMapping("init")
    public Result getById(int id){
        EduTeacher eduTeacher=this.eduTeacherService.getById(id);
        if(ObjectUtils.isEmpty(eduTeacher)){
            return new Result(10004,"查询失败");
        }else{
            return new Result(200,"成功",eduTeacher);
        }
    }




 //查询专业
   @GetMapping("Syslist")
    public List<SysSubject> listAll(){
        return this.sysSubjectService.select();
   }


    @PostMapping("upload")
    public FileUploadResult upload(MultipartFile file) {
        log.info("图片：" + file);
        return fileUploadService.upload(file);

    }

    @GetMapping("Sysint")
    public Result getint(Integer id){
        return this.sysSubjectService.selectByPrimaryKey(id);
    }
    }
